<template>
  <div class="newProfessionBaseInfo">
    <el-breadcrumb separator="/" class="breadcrumb-bottom">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>基础信息管理</el-breadcrumb-item>
      <el-breadcrumb-item>新增专业基本信息</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="fixed-form">
      <el-form :model="newProfessionForm" :rules="NewProfessionRules" ref="newProfessionForm" label-width="100px"
               class="demo-ruleForm">
        <el-form-item label="专业代码" prop="majorId">
          <el-input v-model="newProfessionForm.majorId"></el-input>
        </el-form-item>
        <el-form-item label="学院编号" prop="collegeId">
          <el-input v-model="newProfessionForm.collegeId"></el-input>
        </el-form-item>
        <el-form-item label="专业名称" prop="majorName">
          <el-input v-model="newProfessionForm.majorName"></el-input>
        </el-form-item>
        <el-form-item label="专业简称" prop="majorShortName">
          <el-input v-model="newProfessionForm.majorShortName"></el-input>
        </el-form-item>
        <el-form-item label="学科门类" prop="majorSort">
          <el-select v-model="newProfessionForm.majorSort" placeholder="请选择活动区域" class="max-width">
            <el-option label="理工科" value="理工科"></el-option>
            <el-option label="文史科" value="文史科"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="专业负责人" prop="majorManager">
          <el-input v-model="newProfessionForm.majorManager"></el-input>
        </el-form-item>
        <el-form-item label="教研室主任" prop="teachingDirector">
          <el-input v-model="newProfessionForm.teachingDirector"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('newProfessionForm')">立即创建</el-button>
          <el-button @click="resetForm('newProfessionForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<style>
  /* .newProfessionBaseInfo {
     width: 600px;
     margin: 0 auto
   }*/
  /*.newProfessionBaseInfo .form {
    width: 600px;
    margin: 0 auto
  }*/
</style>
<script>
  export default{
    name: 'newProfessionBaseInfo',
    data(){
      return {
        newProfessionForm: {
          majorId: '',
          collegeId: '',
          majorName: '',
          majorShortName: '',
          majorSort: '',
          majorManager: '',
          teachingDirector: ''
        },
        NewProfessionRules: {
          majorId: [
            {required: true, message: '请输入活动名称', trigger: 'blur'}
          ],
          collegeId: [
            {required: true, message: '请输入活动名称', trigger: 'blur'}
          ],
          majorName: [
            {required: true, message: '请输入活动名称', trigger: 'blur'}
          ],
          majorShortName: [
            {required: true, message: '请输入活动名称', trigger: 'blur'}
          ],
          majorSort: [
            {required: true, message: '请输入活动名称', trigger: 'blur'}
          ],
          majorManager: [
            {required: true, message: '请输入活动名称', trigger: 'blur'}
          ],
          teachingDirector: [
            {required: true, message: '请输入活动名称', trigger: 'blur'}
          ]
        }
      }
    },
    components: {},
    mounted: function () {
      this.$nextTick(function () {

      })
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            console.log(this.newProfessionForm.majorName);
            this.$http.post(this.$until.url + '/majorBaseInfo/addMajor', this.newProfessionForm, {emulateJSON: true}).then(response => {
              //success
              this.$message({
                message: '恭喜你，这是一条成功消息',
                type: 'success'
              });
              this.$router.replace({path: '/ProfessionBaseInfo'});
            }, response => {
              console.log('文件获取失败');
            });
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  }
</script>
